<?php

namespace app\common\logic;

use app\common\library\MemberVo;
use app\common\traits\ModelQuery;

abstract class BaseLogic
{
    use ModelQuery;

    public $model;

    public $memberId;

    abstract public function assignModel();

    public function __construct()
    {
        $this->assignModel();
        $this->memberId = MemberVo::instance()->getMemberId();
        $this->shopId = MemberVo::instance()->getShopId();
        $this->openid = MemberVo::instance()->getMiniOpenId();
    }

    public function generateMeta($paginate): array
    {
        return [
            'current_page' => $paginate->currentPage(),  // 当前页
            'last_page'    => $paginate->lastPage(),     // 最后一页
            'per_page'     => $paginate->listRows(),     // 页面大小
            'total'        => $paginate->total(),        // 总条数
        ];
    }

    /**
     * 日期处理
     * @param $list
     * @param array $times
     * @return mixed
     */
    public function handleDate($list, array $times = ['createtime'])
    {
        foreach ($list as &$li) {
            foreach ($times as $time ){
                $li[$time] = date('Y-m-d H:i:s', $li[$time]);
            }
        }
        return $list;
    }
}